<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #small{
            width: 300px;
            height: 300px;
        }
        #small>img{
            width: 300px;
            height: 300px;
        }
        #slider{
            width: 140px;
            height: 140px;
            background-color: rgba(242, 255, 0, 0.292);
            position: absolute;
            top: 0;
            display: none;
        }
        #big{
            width: 300px;
            height: 300px;
            position: absolute;
            left: 350px;
            top: 0;
            overflow: hidden;
            display: none;
        }
    </style>
</head>
<body>
    <div id="small">
        <img src="fdj.jpg" alt="">
        <div id="slider"></div>
    </div>
    <div id="big">
        <img src="fdj.jpg" alt="">
    </div>
    <script>
        var small = document.getElementById("small");
        var big = document.getElementById("big");
        var slider = document.getElementById("slider");
        var bigImg = document.getElementsByTagName("img")[1];
        small.onmousemove = function(e){
            var even = e || event;
            var x = even.clientX - small.offsetLeft - slider.offsetWidth / 2 ;
            var y = even.clientY - small.offsetTop - slider.offsetHeight / 2;
            var maxX =small.clientWidth - slider.clientWidth;
            var maxY =small.clientHeight - slider.clientHeight;
            if(x<0){
                x=0;
            }
            if(x>maxX){
                x=maxX;
            }
            if(y<0){
                y=0;
            }
            if(y>maxY){
                y=maxY;
            }
            slider.style.top = y + "px";
            slider.style.left = x + "px";
            big.scrollLeft = x/maxX*(bigImg.clientWidth-big.clientWidth);
            big.scrollTop=y/maxY*(bigImg.clientHeight-big.clientHeight);
        }
        small.onmouseenter = function(){
            slider.style.display="block";
            big.style.display="block";
        }
        small.onmouseleave=function(){
            slider.style.display="none";
            big.style.display="none";
        }
    </script>
</body>
</html>